package com.heu.blood.bloodtest.controller;

import com.heu.blood.bloodtest.entity.BloodTestEntity;
import com.heu.blood.bloodtest.entity.PreTestResult;
import com.heu.blood.bloodtest.entity.TestResult;
import com.heu.blood.bloodtest.service.BloodTestService;
import com.heu.blood.bloodtest.vo.BloodSamplePatientReportVo;
import com.heu.blood.bloodtest.vo.BloodSampleReportVo;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 血液检验表
 *
 * @author lrz
 * @email lrz@heu.com
 * @date 2023-08-28 17:09:06
 */
@RestController
@RequestMapping("bloodtest/bloodtest")
public class BloodTestController {
    @Autowired
    private BloodTestService bloodTestService;

    /**
     * 分页条件查询血液样本表信息
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodTestService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据检测单号查询检测信息
     * @param bloodTestId
     * @return
     */
    @GetMapping("/getByTestId")
    public R getByTestId(String bloodTestId){
        List<BloodTestEntity> bloodTestEntityList = bloodTestService.getByTestId(bloodTestId);
        return R.ok().put("data", bloodTestEntityList);
    }

    /**
     * 分页联表条件查询血液样本和检测结果
     * @param params
     * @return
     */
    @RequestMapping("/selectSampleTestPage")
    public R selectSampleTestPage(@RequestParam Map<String, Object> params){
        PageUtils page = bloodTestService.selectSampleTestPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 分页联表条件查询病人血液样本和检测结果
     * @param params
     * @return
     */
    @RequestMapping("/selectSamplePatientTestPage")
    public R selectSamplePatientTestPage(@RequestParam Map<String, Object> params){
        PageUtils page = bloodTestService.selectSamplePatientTestPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		BloodTestEntity bloodTest = bloodTestService.getById(id);

        return R.ok().put("bloodTest", bloodTest);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BloodTestEntity bloodTest){
		String msg = bloodTestService.saveTest(bloodTest);

        return R.ok(msg);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BloodTestEntity bloodTest){
		String msg = bloodTestService.updateTestById(bloodTest);

        return R.ok(msg);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		bloodTestService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询病人样本检测报告
     * @param bloodSampleId
     * @return
     */
    @GetMapping("/queryPatientTestResult")
    public R queryPatientTestResult(String bloodSampleId){
        Map<BloodSamplePatientReportVo, List<TestResult>> report =  bloodTestService.queryPatientTestResult(bloodSampleId);
        return R.ok().put("map", report);
    }

    /**
     * 查询病人输血前检查结果
     * @param bloodSampleId
     * @return
     */
    @GetMapping("/queryPatientPreTestResult")
    public R queryPatientPreTestResult(String bloodSampleId){
        List<PreTestResult> preTestResults = bloodTestService.queryPatientPreTestResult(bloodSampleId);
        return R.ok().put("map", preTestResults);
    }

    /**
     * 查询血液样本检测报告
     * @param bloodSampleId
     * @return
     */
    @GetMapping("/queryTestResult")
    public R queryTestResult(String bloodSampleId){
        Map<BloodSampleReportVo, List<TestResult>> report =  bloodTestService.queryTestResult(bloodSampleId);
        return R.ok().put("map", report);
    }
}
